﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class BasicBase_ExcellenceSoldier_NewExcellenceSoldier : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        NewMethod();

    }

    private void NewMethod()
    {
        string path = Server.MapPath("Files");
        string[] names = System.IO.Directory.GetFiles(path);
        if (names.Count() > 0)
        {
            string name = names[0].Substring(names[0].LastIndexOf("\\") + 1, names[0].Length - names[0].LastIndexOf("\\") - 1);
            DownLoad.NavigateUrl = "Files/" + name;
            DownLoad.Text = name;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string Name = "优秀士兵人才库";
        if (FileUpload1.HasFile)
        {
            string ex = FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf('.') + 1);

            if (FileUpload1.FileContent.Length / 1024 / 1024 > 5)
            {

                lblHy.Text = "提示:上传文档不可大于5M!";
                return;
            }
            else
            {
                string path = Server.MapPath("Files");
                string[] names = System.IO.Directory.GetFiles(path);
                foreach (string aa in names)
                {
                    FileInfo info = new FileInfo(aa);
                    info.IsReadOnly = false;
                    File.Delete(aa);
                }

                FileUpload1.SaveAs(path + "\\" + Name + "." + ex);
                NewMethod();

            }

        }
        else
        {
            lblHy.Text = "请添加文件!";
            return;
        }

    }
}
